package com.hippo.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.hippo.core.config.annotation.RequiresPermissions;
import com.hippo.core.service.FieldMappingService;
import com.hippo.core.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: hippo
 */
@RestController
public class FieldMappingController {

    @Autowired
    private FieldMappingService fieldMappingService;

    @RequiresPermissions("fieldMapping:list")
    @PostMapping("/getFieldMappingList")
    public JSONObject getFieldMappingList(@RequestBody JSONObject data) {
        return fieldMappingService.getFieldMappingList(data);
    }

    @RequiresPermissions("fieldMapping:add")
    @PostMapping("/addFieldMapping")
    public JSONObject addFieldMapping(@RequestBody JSONObject data) {
        CommonUtil.hasAllRequired(data, "name,dataSourceId,mapping");
        return fieldMappingService.addFieldMapping(data);
    }

    @RequiresPermissions("fieldMapping:update")
    @PostMapping("/updateFieldMapping")
    public JSONObject updateFieldMapping(@RequestBody JSONObject data) {
        return fieldMappingService.updateFieldMapping(data);
    }

    @RequiresPermissions("fieldMapping:delete")
    @DeleteMapping("/deleteFieldMapping/{id}")
    public JSONObject deleteFieldMapping(@PathVariable Integer id) {
        return fieldMappingService.deleteFieldMapping(id);
    }


}
